package com.jichangxiu.dynamic.test.service.impl;

import com.jichangxiu.dynamic.test.config.SelectDB;
import com.jichangxiu.dynamic.test.entity.User;
import com.jichangxiu.dynamic.test.mapper.UserMapper;
import com.jichangxiu.dynamic.test.service.UserService;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;

/**
 * @author Jcx
 * @date 2022/11/26 21:24
 */
@Service
@SelectDB(dbName = "t1")
@Transactional(rollbackFor = Exception.class)
public class UserServiceImpl extends BaseServiceImpl<UserMapper, User> implements UserService {

    @Override
    public Future<Boolean> saveUser(User user) {
        return new AsyncResult<>(save(user));
    }

    /**
     * 查询用户列表
     *
     * @return 用户列表
     */
    @Override
    public CompletableFuture<List<User>> myList() {
        List<User> users = list();
        users.forEach(System.out::println);
        return CompletableFuture.completedFuture(users);
    }

}
